package com.hutao.manage.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Properties;

/**
 * ClassName:CacheJdbcUtil
 * Package：com.tele.health.operation.api.util
 * Description:
 *
 * @Date:2020-06-28 14:08
 * @Author:liyutao
 */
public class CacheJdbcUtil {

    private static Logger logger = LoggerFactory.getLogger(CacheJdbcUtil.class);

    private static Properties prop = new Properties();

    private static String driver = null;
    private static String url = null;
    private static String username = null;
    private static String password = null;

    static {
        try {
            driver = "com.intersys.jdbc.CacheDriver";
            url = "jdbc:Cache://172.23.6.198:1972/DHC-APP";
            username = "basb";
            password = "basb123456";
            logger.info("driver=="+driver+"url=="+url+"username=="+username+"password=="+password);
        } catch (Exception e) {
            logger.error("CacheJdbcUtil error!!!"+e);
        }
    }

    public static Connection getConn() {

        Connection conn = null;

        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, username, password);
            logger.error("driver=="+driver+"url=="+url+"username=="+username+"password=="+password);
        } catch (Exception e) {
            logger.error("zskxlog ExamJDBCUtil error!!!"+e);
        }

        return conn;
    }

    public static void closeConn(Connection conn) {

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void closePreStat(PreparedStatement ps) {

        try {
            if (ps != null) {
                ps.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void closeResSet(ResultSet rs) {

        try {
            if (rs != null) {
                rs.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) throws Exception {
        PreparedStatement ps = null;
        Connection con = null;
        ResultSet rs = null;

        String dateStr = "2020-06-12";

        String sql = "call web.DHCHisToOther_InAdmPatientInfoNew(\"2020-06-12\",\"2020-06-12\")";
        
        System.out.println(sql);
        con = CacheJdbcUtil.getConn();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        
        java.util.Date startDate = sdf.parse("2020-07-07");
        try {
			
		
        
        CallableStatement cs = con.prepareCall("{call web.DHCHisToOther_GetBloodGroupList(?)}");
      //给存储过程的参数设置值
        cs.setString(1, "2020-12-18");
       // cs.setString(2, "2020-07-08");
        
        rs = cs.executeQuery();
        


     
        while (rs.next()) {
        	String patientId = rs.getString("ADMID");// HIS内部标识/PatientId
//			String busType = "3"; 
			String patId = rs.getString("PATID"); 
			String type = rs.getString("TYPE"); 
//			String orgaCode = "49557184-0";//cacheDBRs.getString("ORGANAME"); 
//			String orgaName = "山东省立医院";//cacheDBRs.getString("ORGANAME"); 
			String name = rs.getString("NAME"); 
			String patNo = rs.getString("PATNO"); 
			String mrId = rs.getString("MEDNO"); 
			String onlyId = rs.getString("IPNO"); 
			String disDate = rs.getString("DISDATE");
			String bloodList = rs.getString("BLOODLIST");
			
			System.out.println(patientId+"--"+type+"--"+patId+"--"+name+"--"+patNo+"--"+mrId+"--"+onlyId+"--"+disDate+"--"+bloodList);
        }
        
        } catch (Exception e) {
			e.printStackTrace();
		}
    }




}
